The NumericUpDown Control in C#.Net
The NumericUpDown control provides a way to select a number that falls between a minimum and a maximum value.
The numeric value can be incremented or decremented by clicking the up or
down buttons of the control. The user can also enter a value.
How to use NumericUpDown Control
Drag and drop NumericUpDown Control and a textbox from the toolbox on window Form.
Code: Write code on the ValueChanged event of NumericUpDown control.
Double click on ValueChanged event.
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
//selected value will show in TextBox
textBox1.Text = numericUpDown1.Value.ToString();
}
Run the project
When you will run the project the initial value of NumericUpDown will be 0. Now when you change the value of NumericUpDown then changed value will also show in textbox.
NumericUpDown Control Properties
DecimalPlaces: Set the number of decimal places to display in NumericUpDown Control.
UpDownAlign: Set positions the arrow buttons on the left or the right side of the NumericUpDown. The default value is Right.
Increment: Gets or sets the value to increment or decrement the NumericUpDown.
Example:
private void frmNumericUpDown_Load(object sender, EventArgs e)
{
//Increment the NumericUpDown value
numericUpDown1.Increment = 5;
}
NumericUpDown value will be incremented 5 at each up button click.
Hexadecimal : Hexadecimal property used to show value in Hexadecimal format in NumericUpDown. The default value is false.
Example:
private void frmNumericUpDown_Load(object sender, EventArgs e)
{
// allow to show value in Hexadecimal format
numericUpDown1.Hexadecimal = true;
}
Leave Comment